<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link th:href="@{/plugin/layui/css/layui.css}" rel="stylesheet"/>
<link th:href="@{/css/step.css}" rel="stylesheet"/>
<script type="text/javascript" th:src="@{/plugin/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/plugin/mylayui/step.js}"></script>
<script type="text/javascript" th:src="@{/js/common.js}"></script>
<body>
<div class="layui-step">
    <div class="layui-step-content layui-clear">
        <div class="layui-step-content-item">
            1
        </div>
        <!--第二步-->
        <div class="layui-step-content-item layui-step-title-item step-current">
            <div id="table-tea" style="display: block">
                <table class="layui-hide" id="test" lay-filter="table"></table>
            </div>
            <!--评价展示-->
            <div id="table-zb">
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="toolBar">
    <a class="layui-icon" style="font-size: 25px; color: #1AA094;" lay-event="confirms">&#xe611;评价</a>
</script>
<script type="text/html" id="sexTpl">
    {{#  if(d.teaSex ==0){ }}
    {{'女'}}
    {{#  }  else { }}
    {{'男'}}
    {{#  } }}
</script>
<script>
    //var $;
    //var table;
    layui.config({
        base: "/plugin/mylayui/"
    }).use(['jquery', 'step', 'table', 'form'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var step = layui.step;
        var form = layui.form;
        step.render({
            elem: '.layui-step',
            isOpenStepLevel: true
        });
        $(".next").on("click", function () {
            step.next();
        });
        step.goStep(2);
        var id = getParam('id');
        var teacherId;
        table.render({
            elem: '#test'  //绑定table id
            , url: 'course/queryTeacherByCourseId?id=' + id  //数据请求路径
            , cellMinWidth: 80
            , cols: [
                [
                {type: 'numbers'}
                , {field: 'teaBianhao', title: '编号',align: 'center'}
                , {field: 'teaRealname', title: '教师真实名称',align: 'center'}
                , {field: 'teaSex', title: '性别', templet: '#sexTpl',align: 'center'}
                , {field: 'teaAge', title: '年龄',align: 'center'}
                , {fixed: 'right', title: '操作', width: 180, align: 'center', toolbar: '#toolBar'}//一个工具栏  具体请查看layui官网
            ]
            ]
            , page: true   //开启分页
            , limit: 10   //默认十条数据一页
            , limits: [10, 20, 30, 50]  //数据分页条
            , id: 'testReload'
        });
        table.on('tool(table)', function (obj) {
            var data = obj.data;
            teacherId=data.teaId;
            if (obj.event === 'confirms') {
                var option={};
                option.teaId=data.teaId;
                option.courseId=id;
                $.post("teacher/eva_check",option,function (result) {
                    if (result.code != "100") {
                        layer.msg(result.message, {icon: 5});
                    } else {
                        $("#table-tea").css("display", "none");
                        $.getJSON("first/selectList", function (msg) {
                            var html = "<form class=\"layui-form\" action=\"\"><div class=\"layui-form-item\">";
                            for (var i in msg) {
                                html = html + "<div class=\"layui-inline\">\n" +
                                    "      <div class=\"layui-input-inline\">\n" +
                                    "指标名称:" + msg[i].indexname + "<input type=\"NUMBER\" name=\"fenshu" + i + "\" onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" onafterpaste=\"this.value=this.value.replace(/\\D/g,'')\" placeholder='请打分:1-100之间' lay-verify=\"required\" id='fenshu" + i + "' data-var='" + msg[i].weight + "' data-id='"+msg[i].id+"'  autocomplete=\"off\" class=\"layui-input\">" +
                                    "      </div>\n" +
                                    "    </div>";
                            }
                            html = html + "</div><div class=\"layui-form-item\" ><div class=\"layui-input-block\">\n" +
                                "            <button class=\"layui-btn\" lay-submit=\"\" lay-filter=\"saveOrAdd\">保存</button>\n" +
                                "        </div>\n" +
                                "    </div></form>"
                            $("#table-zb").html(html);
                            form.render();
                        });
                    }
                });
            }
        });

        form.on('submit(saveOrAdd)', function (data) {
            var datas = data.field;
            var arr=new Array();
            for (var i in datas) {
                var zb = $("#" + i).attr("data-var");
                var score = datas[i];
                var result = zb * score;
                var option={};
                option.score=result;
                option.teaId=teacherId;
                option.evId=parseInt($("#"+i).attr("data-id"));
                option.courseId=parseInt(id);
                arr.push(option);
            }
            var datas=JSON.stringify(arr);
            $.post("pj/add",{datas:datas},function (result) {
                if(result.code=="100"){
                    layer.msg("评分成功");
                    setTimeout(function () {
                        $(window.parent.document).find(".href-url")[1].click();
                    }, 2000);
                }else{
                    layer.msg(result.message);
                }
            });
            return false;
        });
    });
</script>

</html>